package cn.wolfcode.p2p.website.controller;

import cn.wolfcode.p2p.base.domain.LoginInfo;
import cn.wolfcode.p2p.base.exception.DisplayableException;
import cn.wolfcode.p2p.base.service.ILoginInfoService;
import cn.wolfcode.p2p.base.util.JSONResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Created by wolfcode on 2018/7/20.
 */
@Controller
public class LoginInfoController {
	@Autowired
	private ILoginInfoService loginInfoService;

	@RequestMapping("/userRegister")
	@ResponseBody
	public JSONResult userRegister(String username, String verifycode, String password, String confirmPwd,
			HttpSession session) {
		JSONResult result = null;
		try {
			loginInfoService.register(username, verifycode, password, confirmPwd, session);
			result = new JSONResult("注册成功");
		} catch (DisplayableException ex) {
			result = new JSONResult(false, ex.getMessage());
		} catch (Exception e) {
			// 把错误信息记录到服务器中日志文件中,方便排查问题.
			result = new JSONResult(false, "系统异常,请联系管理员!");
			e.printStackTrace();
		}
		return result;
	}

	@RequestMapping("/checkPhoneNumber")
	@ResponseBody
	public Boolean checkPhoneNumber(String username) {
		return loginInfoService.checkPhoneNumber(username);
	}
}
